<?php
	error_reporting(E_ALL ^ E_NOTICE);
	
	// Load JSON engine.
	require_once 'json.inc';
	$result = array();
	$output_buffer = 'Empty action';
    
    $json = new Services_JSON();
    
	if (! empty($_REQUEST['action']))                       
	{
		ob_start(); //start output buffering  
		$result = include_once('ajax/ajax.' . $_REQUEST['action'] . '.inc');
		//stop output buffering and save buffer
		$output_buffer = ob_get_clean(); 
	}
	if (! empty($result))
	{       
		$result['output'] = $output_buffer;
		//print (Services_JSON::encode($result));
        print ($json->encode($result));
	}
	else  //if error occurred during request processing
	{
		//print (Services_JSON::encode(array('output' => $output_buffer)));
        print ($json->encode(array('output' => $output_buffer)));
	}
?>
